package com.up360.rapidcalc.aerolite.model
{
    import com.up360.rapidcalc.aerolite.controller.BasicCtrl;
    import com.up360.rapidcalc.aerolite.controller.FortCtrl;
    import com.up360.rapidcalc.aerolite.swc.FortUI;
    
    import flash.display.DisplayObject;
    import flash.display.MovieClip;
    import flash.geom.Point;

    /**
     * @author Tunie
     * @date   May 2, 2013
     * 炮台
     */
    public class Fort extends GameElement
    {
        public static const NORMAL:int=1;
        public static const STOP:int=2;
        public static const BLOWUP:int=3;
        /**
         *炮座 
         */
        public var gunPlatform:GunPlatform;
        /**
         *激光束 
         */
        public var laserBeam:LaserBeam;
        /**
         *炮管 
         */
        public var barrel:Barrel;
        
        private var _ctrl:BasicCtrl;
        public function Fort(ui:FortUI)
        {
            super();
            _ui=ui;
            //
            barrel=new Barrel();
            barrel.ui=ui.mcBarrel;
            //
            gunPlatform=new GunPlatform();
            gunPlatform.ui=ui.mcGunPlatform;
            //
            laserBeam=new LaserBeam();
            addChild(laserBeam);
            //
            addChild(_ui);
        }
        
        /**
         * 更新炮座状态
         * @param state
         */
        public function updateGunPlatform(state:int):void
        {
            gunPlatform.state=state;
        }
        /**
         *开火 
         */
        public function fire(obj:GameElement):void
        {
            //取得obj的坐标
            var b_objLocal:Point=obj.local();
            //
            laserBeam.showLine(b_objLocal,local());
            //
            barrel.state=Barrel.FIRE;
            //
            
        }

        public function set ctrl(value:BasicCtrl):void
        {
            _ctrl = value;
            _ctrl.target=this;
        }
        
        override public function clear():void
        {
            laserBeam.clear();
        }
        

    }
}